package extract;

import control.CConnection;
import control.CMember;
import control.CBiologist;
import model.Member;
import model.Biologist;
import java.util.Random;
import java.io.*;
import java.sql.*;

public class ExtractMemberBiologist {
	public static void main(String args[]) {
		CConnection cn = new CConnection();
		
		try {
			cn.createConnection();
			CMember cm = new CMember(cn);
			CBiologist cb = new CBiologist(cn);
			Random rand = new Random();
			
			BufferedReader input = new BufferedReader(new FileReader("data/vestFuvest.txt"));
			String line = null;
			String[] countrys = {"Brazil", "Bolivia", "Uruguay", "Paraguay", "USA", "Germany", "France", "Japan", "Mexico", "India"};
			
			for(int i = 1; i <= 120; i++) {
				String name = "";
				String pda = "";
				
				int randomguy = rand.nextInt(200);
				
				for(int j = 0; j <= randomguy; j++)
					line = input.readLine();
					
				if(line.equals(""))
					line = input.readLine();
				
				name = line.substring(0, 40).trim();
				pda = line.substring(49).trim();
				
				int ano = rand.nextInt(12) + 2000;
				Member m = new Member(name, java.sql.Date.valueOf(ano + "-01-01"), countrys[rand.nextInt(countrys.length)], pda, i, rand.nextInt(74)+1);
				cm.create(m);
			}
			
			for(int i = 1; i <= 40; i++) {
				String name = "";
				String id = "";
				
				int randomguy = rand.nextInt(200);
				for(int j = 0; j <= randomguy; j++)
					line = input.readLine();
					
				if(line.equals(""))
					line = input.readLine();
				
				name = line.substring(0, 40).trim();
				id = line.substring(41, 48).trim();
				
				int ano = rand.nextInt(12) + 2000;
				Biologist b = new Biologist(id, name, java.sql.Date.valueOf(ano + "-01-01"), countrys[rand.nextInt(countrys.length)], rand.nextInt(77));
				cb.create(b);
			}
			
			System.out.println("Members and Biologists added successfully.");
		}
		catch (ClassNotFoundException e) {
			System.err.println("Couldn't connect to Derby Database.");
		}
		catch (SQLException e) {
			System.err.println("Error in SQL Statement.");
		}
		catch (FileNotFoundException e) {
			System.err.println("File not found!");
		}
		catch (IOException e) {}
	}
}